// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/dwio/dwrf/reader/stream_labels.h>

namespace kumo::pollux::dwrf {

std::string_view StreamLabels::label() const {
  return label_.empty() ? "/" : label_;
}

StreamLabels StreamLabels::append(std::string_view suffix) const {
  const size_t bufSize = label_.size() + suffix.size() + 1;
  auto* buffer = pool_.allocateFixed(bufSize);
  if (!label_.empty()) {
    ::memcpy(buffer, label_.data(), label_.size());
  }
  buffer[label_.size()] = '/';
  if (!suffix.empty()) {
    ::memcpy(buffer + label_.size() + 1, suffix.data(), suffix.size());
  }
  return StreamLabels(pool_, {buffer, bufSize});
}

} // namespace kumo::pollux::dwrf
